<template>
  <div>
    <Table :columns="testListColumns"  stripe height="800"  :data="testListData"></Table>
    <Button type="primary" shape="circle" @click="addNewConfig"> 新增</Button>
  </div>
</template>

<script>

import bus from 'emitvue';

const electron = require('electron');
const store = electron.remote.getGlobal('store');
const utils = require('./lib/utils');
import {v4} from 'uuid';

export default {
  name: "AutoTestList",
  data() {
    return {
      testListColumns: [
        {
          title: '配置名称',
          key: "name",
        },
        {
          title: "操作",
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                on: {
                  click: () => {
                    this.removeTestConfig(params.index)
                  }
                }
              }, 'Delete')
            ]);
          },
          width:"100px",
        }
      ],
      testListData: [
      ],
    }
  },
  methods: {
    removeTestConfig(index) {
      this.testListData.splice(index, 1);
      store.set('testConfig', JSON.stringify(this.testListData));
      this.$Message.success("删除成功");
    },
    addNewConfig() {
      let name = v4();
      this.testListData.push({
        name,
        data: {
          name,
        },
      });
      store.set('testConfig', JSON.stringify(this.testListData));
    },

    // 初始化的时候自动获取配置
    getAllTestConfig() {
      let config = store.get('testConfig');
      if (!config) {
        config = [];
        store.set('testConfig', JSON.stringify(config));
      }
      config = utils.safeJsonParse(config);
      console.log('获取的自动化测试配置为:',config );
      this.testListData = config;
    },
  },
  components: {},
  created() {
    this.getAllTestConfig();
  },

}
</script>

<style scoped>

</style>
